/* Box blur (simple smooth) problem optimized using CUDA and motion blur. June 2014.
 * Felipe Osorio Thome 7696409 <f.o.thome@gmail.com>.
 * Thales Andrade 7573527.
 * Vitor Lima 7573361.
 *
 * This work is based on Convolution paper by Nvidia Corporation. */

#ifndef SMOOTH_H
#define SMOOTH_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define fatal(expression) do{ \
  if(expression) {fprintf(stderr, "%s: %d: %s\n", __FILE__, __LINE__, strerror(errno)); exit(EXIT_FAILURE);} \
  } while(0)

/* Round "a / b" to nearest higher integer value. */
#define iDivUp(a,b) ((a % b != 0) ? (a / b + 1) : (a / b))

#define KERNEL_RADIUS 2
#define KERNEL_LENGTH (2 * KERNEL_RADIUS + 1)

/* KERNEL_RADIUS_ALIGNED, ROW_TILE_W, COLUMN_TILE_W and image width
 * must be multiple of 16 (32?) for coalesced global memory operations. */
#define KERNEL_RADIUS_ALIGNED 16
#define ROW_TILE_W 128
#define COLUMN_TILE_W 16
#define COLUMN_TILE_H 48

typedef struct {
  int xsize;
  int ysize;
  int maxrgb;
} IMG_HEADER;

typedef struct {
  int *rarray;
  int *garray;
  int *barray;
} IMG_DATA;

FILE *xfopen(char *, char *);
void *xcalloc(unsigned long int, int);

extern "C" void convolutionRowsGPU(int *, int *, int, int);
extern "C" void convolutionColumnsGPU(int *, int *, int, int);

#endif
